package gold.digger;

import gold.utils.InputUtil;

/**
 * Created by fanzhenyu02 on 2021/12/10.
 * common problem solver template.
 */
public class LC984 {
    public long startExecuteTime = System.currentTimeMillis();


    class Solution {
        public String strWithout3a3b(int a, int b) {
            StringBuilder ans = new StringBuilder();
            char aCh = a >= b ? 'a' : 'b', bCh = a >= b ? 'b' : 'a';
            int na = a >= b ? a : b, nb = a >= b ? b : a;

            int x = na - nb, y = 2 * nb - na;
            if (x >= 0 && y >= 0) {
                // 情况1: 尾号是 空 命中
                fillAB(ans, x, y, aCh, bCh);
                return ans.toString();
            }

            x = na - nb - 1;
            y = 2 * nb - na + 1;
            if (x >= 0 && y >= 0) {
                // 情况2: 尾号是 aCh 命中
                fillAB(ans, x, y, aCh, bCh);
                ans.append(aCh);
                return ans.toString();
            }

            x = na - nb + 1;
            y = 2 * nb - na - 1;
            if (x >= 0 && y >= 0) {
                // 情况3: 尾号是 bCh 命中
                fillAB(ans, x, y, aCh, bCh);
                ans.append(bCh);
                return ans.toString();
            }

            x = na - nb - 2;
            y = 2 * nb - na + 2;
            // 情况4: 尾号是 aCh aCh 命中
            fillAB(ans, x, y, aCh, bCh);
            ans.append(aCh).append(aCh);
            return ans.toString();
        }

        public void fillAB(StringBuilder ans, int x, int y, char aCh, char bCh) {
            for (int i = 0; i < x; i++) ans.append(aCh).append(aCh).append(bCh);
            for (int i = 0; i < y; i++) ans.append(aCh).append(bCh);
        }
    }

    public void run() {
        Solution solution = new Solution();
        System.out.println(solution.strWithout3a3b(7, 3));
        System.out.println(solution.strWithout3a3b(1, 2));
        System.out.println(solution.strWithout3a3b(1, 4));
        System.out.println(solution.strWithout3a3b(4, 1));
    }

    public static void main(String[] args) throws Exception {
        LC984 an = new LC984();
        an.run();

        System.out.println("\ncurrent solution total execute time: " + (System.currentTimeMillis() - an.startExecuteTime) + " ms.");
    }
}
